#pragma once
#include "CTileBrush.h"
#include "REQUEST.h"

class CImageSource;


class CBitmapImageReportCallback;

class CImageBrush :
	public CTileBrush
{
protected: 
	CImageBrush(CCoreServices * pCore);
protected: 
	virtual ~CImageBrush();
public: 
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual XUINT32 GetTypeIndex() const;
	virtual HRESULT AddEventListener(CDependencyProperty * pdp, CValue * pValue, XINT32 iListenerType, CValue * pResult, XINT32 fHandledEventsToo);
	virtual HRESULT RemoveEventListener(CDependencyProperty * pdp, CValue * pValue);
protected: 
	virtual HRESULT EnterImpl(CDependencyObject * pNamescopeOwner, struct EnterParams params);
protected: 
	virtual HRESULT LeaveImpl(CDependencyObject * pNamescopeOwner, struct LeaveParams params);
public: 
	virtual HRESULT CreateBrushSpan(const CMILMatrix * pWorldTransform, const struct XRECTF_WH * pBrushBounds, struct IBrushSpan * * ppBrushSpan);
	virtual HRESULT ReloadSoftwareSurfaceIfReleased();
	virtual HRESULT Lock(void * * ppAddress, XINT32 * pnStride, XUINT32 * puWidth, XUINT32 * puHeight);
	virtual XBOOL UnLock();
	virtual struct IPALSurface * GetSurface();
	virtual void SetSurface(struct IPALSurface * pSurface, XBOOL fSetMediaSurface);
	virtual XINT32 IsOpaque();
	HRESULT ReloadImage(struct IImageReportCallback * pImageErrorCallback);
	virtual HRESULT HasProtectedContent(XBOOL * pfHasProtectedContent);
	XBOOL HasDimensions();
	virtual struct IPALSurface * GetSoftwareSurface();
	HRESULT GetSoftwareSurfaceForPrinting(struct IPALSurface * * ppSoftwareSurface);
	virtual void GetNaturalBounds(struct XRECTF_WH * pNaturalBounds);
	virtual HRESULT SetValue(CDependencyProperty * pdp, CValue * pValue);
	void FireImageDownloadEvent(XFLOAT downloadProgress);
	HRESULT FireImageFailed(XBOOL iErrorCode);
	HRESULT FireImageOpened();
	void RemoveCallback();
	virtual HRESULT EnsureAndUpdateHardwareResources(HWTextureManager * pTextureManager, CRenderTarget * pRenderTarget, SurfaceCache * pSurfaceCache);
	virtual XBOOL IsTiledSurface();
	HRESULT GetVisibleImageSourceBounds(const struct XRECTF_RB * pWindowBounds, struct XRECTF_WH * pBounds);
	virtual CTiledSurface * GetTiledSurfaceNoRef();
	virtual HWTexture * GetHardwareSurface();
	virtual HRESULT HandleLostResources(SurfaceCache * pSurfaceCache);
	CImageSource * m_pImageSource;
	XFLOAT m_downloadProgress;
private: 
	XUINT32 m_cLockCount;
	CXcpList<REQUEST> * m_pEventList;
	CBitmapImageReportCallback * m_pBitmapImageReportCallback;
	struct IImageReportCallback * m_pImageReportCallback;
public: 
	virtual HRESULT UpdateAcceleratedBrush(const struct D2DRenderParams & renderParams);
	virtual HRESULT GetPrintBrush(const struct D2DRenderParams & printParams, struct IPALAcceleratedBrush * * ppBrush);


};